package com.ehualu.getes.until;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * @Author: 吴敬超
 * @Date: 2019/11/15 11:35
 */
public class TimeUntil {

    public String dateToStringtuic(String intime) {
        SimpleDateFormat sdfdc = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

        Date datestrdate = null;
        try {
            datestrdate = sdfdc.parse(intime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(datestrdate);

        cal.add(Calendar.HOUR, -8);


//        cal.add(Calendar.MINUTE, 30);
        Date d2 = cal.getTime();

        String outtime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(d2);

        System.out.println(outtime);
        return outtime;
    }

    public static String timdtun(String s) {

        Date date = new Date();

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);

//        时间向前推七天
        cal.add(Calendar.DATE, -7);

        Date dabef = cal.getTime();


//        return res;
        return s;
    }


    public String timeturnuntil(String intime, int snum) {
        SimpleDateFormat sdfdc = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

        Date datestrdate = null;
        try {
            datestrdate = sdfdc.parse(intime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(datestrdate);

        cal.add(Calendar.SECOND, snum);


//        cal.add(Calendar.MINUTE, 30);
        Date d2 = cal.getTime();

//        String outtime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(d2);
        String outtime = sdfdc.format(d2);

        System.out.println(outtime);
        return outtime;
    }


/*
    public static void main(String[] args) {


        TimeUntil timeUntil = new TimeUntil();
//        timeUntil.dateToStringtuic("2019-11-03T00:00:06.000Z");


        String str1 = timeUntil.timeturnuntil("2019-11-03T00:00:06.000Z", -10);
        String str2 = timeUntil.timeturnuntil("2019-11-03T00:00:06.000Z", 10);

        System.out.println("str1：" + str1);

        System.out.println("str2：" + str2);
//
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
//
//
//        Date firstdate = null;
//        Date lastdate = null;
//        try {
//            firstdate = simpleDateFormat.parse("2019-11-03T00:33:06.000Z");
//            lastdate = simpleDateFormat.parse("2019-11-03T00:34:06.000Z");
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        long firstdatelong = firstdate.getTime();
//        long lastdatelong = lastdate.getTime();
//        int stimecz = (int) ((firstdatelong - lastdatelong) / (1000));
//
//
//        System.out.println("两个时间之间的秒差为：" + stimecz);
//
//
//        int absstimecz = Math.abs(9);
//
//        System.out.println("两个时间之间的秒差绝对值为：" + absstimecz);


//        Date date = new Date();
//        String res = simpleDateFormat.format(date);
//        System.out.println("********当前时间转换时区后*********" + res);
//
//        try {
//            Thread.sleep(5000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//
//        System.out.println("********当前时间转换时区后*********" + res);

    }
*/

}
